#include "customtextedit.h"
#include "ui_customtextedit.h"

CustomTextEdit::CustomTextEdit(QWidget *parent) :
    QTextEdit (parent),
    ui(new Ui::CustomTextEdit)
{
    ui->setupUi(this);

    setFocusPolicy(Qt::StrongFocus);
}

CustomTextEdit::~CustomTextEdit()
{
    delete ui;
}

void CustomTextEdit::keyPressEvent(QKeyEvent *event)
{
    // 按下shift控制按键
    if(event->modifiers() == Qt::ShiftModifier)
    {
        switch(event->key())
        {
            case Qt::Key_Enter:insertPlainText("\n");
                break;
            case Qt::Key_Return:insertPlainText("\n");
                break;
        }
    }
    else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
        qDebug()<<"emit sendButtonPressed()";
        // 单独的Enter键，触发发送按键的逻辑
        emit sendButtonPressed();
    }
    else
    {
        // 对于其他按键，调用基类的keyPressEvent
        QTextEdit::keyPressEvent(event);
    }

}
